<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <script>
       var jsonStr='{"name":"张三","age":18,"hobby":["吃饭","睡觉","打豆豆"],"teacher":{"name":"李四","age":20}}';
        console.log(jsonStr);
        
        var json1=JSON.parse(jsonStr); // 解析JSON字符串
        console.log(json1);
        console.log(json1.name); // 访问属性
        console.log(json1.hobby[1]); // 访问属性
        console.log(json1.teacher.name); // 访问嵌套对象的属性
        var jsonStrStr=JSON.stringify(json1); // 将对象转换为JSON字符串
        console.log(jsonStrStr);
    </script>
</head>
<body>
     
</body>
</html>